using Microsoft.EntityFrameworkCore;
using System.Reflection;
using Traceability.Infrastructure;
using Traceability.Infrastructure.Implement;
using Traceability.Infrastructure.Interfance;

namespace Traceability.App
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            // Add services to the container.

            builder.Services.AddControllers();
            // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
            builder.Services.AddEndpointsApiExplorer();
            builder.Services.AddSwaggerGen(x => x.IncludeXmlComments(AppContext.BaseDirectory + "Traceability.App.xml", true));

            builder.Services.AddDbContext<SCDbContext>(x=>x.UseSqlServer(builder.Configuration.GetConnectionString("con")));
            builder.Services.AddMediatR(x=>x.RegisterServicesFromAssemblies(Assembly.GetExecutingAssembly()));
            builder.Services.AddScoped(typeof(IBaseRespository<>),typeof(BaseRespository<>));
            builder.Services.AddAutoMapper(typeof(Myautomapper));
            var app = builder.Build();

            // Configure the HTTP request pipeline.
            if (app.Environment.IsDevelopment())
            {
                app.UseSwagger();
                app.UseSwaggerUI();
            }

            app.UseAuthorization();

            app.UseCors(x=>x.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin());

            app.MapControllers();

            app.Run();
        }
    }
}
